﻿using Application.Users.Interfaces;
using Application.Users.Models;
using Domain.ValueObjects;
using MediatR;

namespace Application.Users.Queries.GetUser;



/// <summary>
/// 用户登录接收查询模型
/// </summary>
/// <param name="PhoneNumber"></param>
/// <param name="Password"></param>
public record UserLoginQuery(string PhoneNumber, string Password) : IRequest<UserItem?>;

/// <summary>
/// 通过phoneNumber和passwordHash查找用户信息
/// </summary>
/// <param name="repo"></param>
public class UserLoginHandler(IUserReadRepository repo) : IRequestHandler<UserLoginQuery, UserItem?>
{
    public Task<UserItem?> Handle(UserLoginQuery request, CancellationToken cancellationToken)
    {
        return repo.AuthenticateByPhoneNumberAsync(PhoneNumber.Create(request.PhoneNumber),
            request.Password, cancellationToken);
    }
}